﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Diagnostics;

namespace jaysJourney_v01.Utils.Blocks.Interactive
{
    public abstract class InteractiveBlock
    {
        /**
         * MEMBER VARIABLES
         * */

        // From Parent

        protected SpriteBatch parentSpriteBatch;

        // Common

        protected Vector2 position;
        protected Vector2 size;

        protected bool isTriggered;
        protected bool toRemove;

        // Textures

        protected SpriteAnimator idleAnimation;
        protected SpriteAnimator triggerAnimation;

        /**
         * METHODS
         * */

        // Constructor

        public InteractiveBlock(SpriteBatch parent, Vector2 position, Vector2 size, SpriteAnimator idleAnimation, SpriteAnimator triggerAnimation)
        {
            this.parentSpriteBatch = parent;
            this.position = position;
            this.size = size;
            this.idleAnimation = idleAnimation;
            this.triggerAnimation = triggerAnimation;

            this.idleAnimation.play();
            this.triggerAnimation.play();

            this.isTriggered = false;
        }

        // UPDATE

        public void updateBase(GameTime gameTime)
        {
            update(gameTime);
        }

        // DRAW

        public void drawBase(GameTime gameTime, Vector2 curZero)
        {
            Vector2 newPos = position - curZero; // calc cam-depending position

            if (!isTriggered) idleAnimation.animate(gameTime, newPos, true);
            else triggerAnimation.animate(gameTime, newPos, true);

            draw(gameTime);
        }

        // trigger base

        public void triggerBase()
        {
            this.isTriggered = true;

            trigger();
        }

        // ABSTRACT METHODS
        public abstract void update(GameTime gameTime);
        public abstract void draw(GameTime gameTime);
        public abstract void trigger();

        // get position

        public Vector2 getPosition()
        {
            return this.position;
        }

        // reset triggerAnimation

        public void resetTriggerAnimation()
        {
            this.triggerAnimation.reset();
        }

        // is block to remove

        public bool isBlockToRemove()
        {
            return this.toRemove;
        }
    }
}
